/*
 * Session.h
 *
 *  Created on: Dec 1, 2012
 *      Author: mxx
 */

#ifndef SESSION_H_
#define SESSION_H_
#include <vector>

#include <Wt/Auth/Login>

#include <Wt/Dbo/Session>
#include <Wt/Dbo/ptr>
#include <Wt/Dbo/backend/Sqlite3>

#include "Worker.h"
using namespace Wt;



namespace DataCenter
{
typedef Auth::Dbo::UserDatabase<AuthInfo> UserDatabase;
class Session
{
public:
	static void configureAuth();
	Session();
	virtual ~Session();
	Wt::Auth::AbstractUserDatabase& users();
	Wt::Auth::Login& login()
	{
		return login_;
	}

	std::vector<Worker> topUsers(int limit);

	/*
	 * These methods deal with the currently logged in user
	 */
	std::string userName() const;
	void setLastLogin(void);

	static const Wt::Auth::AuthService& auth();
	static const Wt::Auth::AbstractPasswordService& passwordAuth();
	static const std::vector<const Wt::Auth::OAuthService *>& oAuth();

private:
	Wt::Dbo::backend::Sqlite3 sqlite3_;
	mutable Wt::Dbo::Session session_;
	UserDatabase *users_;
	Wt::Auth::Login login_;

	Wt::Dbo::ptr<Worker> user() const;
};

} /* namespace DataCenter */
#endif /* SESSION_H_ */
